<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms" layout="column">
  <div class="gv-form">
    <form name="$ctrl.notifTemplateForm">
      <div class="gv-form-content" layout="column">
        <h3>{{$ctrl.notifTemplate.description}}</h3>
        <p ng-if="$ctrl.isTemplateToInclude">
          To include this template in another template, use <code>&lt;#include "{{$ctrl.notifTemplate.name}}" /&gt;</code>
        </p>
        <div layout="column">
          <div layout="row">
            <md-input-container class="md-block" flex-gt-sm>
              <md-switch ng-model="$ctrl.overrideModeEnabled" aria-label="Override default template" ng-disabled="$ctrl.readonlyMode">
                Override default template
              </md-switch>
            </md-input-container>
          </div>

          <md-input-container class="md-block" flex-gt-sm ng-if="!$ctrl.isTemplateToInclude">
            <label>Title</label>
            <input
              name="title"
              ng-model="$ctrl.notifTemplate.title"
              required
              type="text"
              ng-disabled="!$ctrl.overrideModeEnabled || $ctrl.readonlyMode"
            />
            <div class="hint" ng-if="$ctrl.notifTemplateForm.title.$valid || $ctrl.notifTemplateForm.title.$pristine">
              Title of the notification
            </div>
            <div ng-messages="$ctrl.notifTemplateForm.title.$error">
              <div ng-message="required">Notification title is required.</div>
            </div>
          </md-input-container>

          <md-input-container ng-class="{'gv-notification-template-content-disabled': !$ctrl.overrideModeEnabled || $ctrl.readonlyMode}">
            <label>Content</label>
            <textarea
              ui-codemirror
              ui-codemirror-opts="{lineWrapping: true, readOnly: ($ctrl.overrideModeEnabled ? false : 'nocursor')}"
              ng-model="$ctrl.notifTemplate.content"
              required
            >
            </textarea>

            <div class="hint" ng-if="$ctrl.notifTemplateForm.content.$valid || $ctrl.notifTemplateForm.content.$pristine">
              Content of the notification
            </div>
            <div ng-messages="$ctrl.notifTemplateForm.content.$error">
              <div ng-message="required">Notification content is required.</div>
            </div>
          </md-input-container>
        </div>

        <md-card-action layout="row">
          <div class="md-actions gravitee-api-save-button" layout="row">
            <md-button
              ng-disabled="$ctrl.notifTemplateForm.$invalid || $ctrl.notifTemplateForm.$pristine || $ctrl.readonlyMode"
              ng-click="$ctrl.save()"
              permission
              permission-only="['organization-notification_templates-u']"
              class="md-raised md-primary"
            >
              Save
            </md-button>
            <md-button
              class="md-raised"
              type="button"
              ng-click="$ctrl.reset()"
              ng-disabled="$ctrl.notifTemplateForm.$invalid || $ctrl.notifTemplateForm.$pristine || $ctrl.readonlyMode"
            >
              Reset
            </md-button>
          </div>
        </md-card-action>
      </div>
    </form>
  </div>
</div>
